package com.example.administrator.uiautomator;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;

import com.example.administrator.uiautomator.utils.Finder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Created by Administrator on 2017/7/4.
 */


@RunWith(AndroidJUnit4.class)
///说明用androidJunit4
public class AddContentTest {
    //声明一个 UiDevice，因为所有的UIAutomat都通过这个device来实现；
    private UiDevice device;
    Finder finder;
    String[] numbers = {"13559494112","13559494113","13559494114","13559494115","13559494116"};

    @Before
    public void setUp() throws Exception {
        //实例化 UiDevice
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        finder = new Finder(device);
    }

    @Test
    public void name() throws Exception {
        finder.findById("com.tencent.mm:id/fh").click();
        finder.findById("com.tencent.mm:id/fh", 1).click();

        UiObject2 search = finder.findById("com.tencent.mm:id/gz");
        search.click();
        for (String number : numbers){
            search = finder.findById("com.tencent.mm:id/gz");
            search.click();
            search.clear();
            search.setText(number);
            Thread.sleep(3000);
            device.pressEnter();
            if (device.findObject(By.text("该用户不存在"))  == null){
                search.clear();
            }else {
                device.findObject(By.res("com.tencent.mm:id/h4")).click();
            }
        }

    }

    @After
    public void tearDown() throws Exception {


    }
}
